<?php
/**
 * 商户
 */

use app\config\Db;
use Core\Result\Result;
use Core\Common\Common;
require_once "Order.php";

/**
 * 获取商户信息 TODO
 * @param $data
 * @return array
 */
function queryMerchantInfo($data)
{
    $sid = $data["sid"];
    $type = $data["type"];
    $db = new Db();
    switch ($type) {
        case 1:
            $offlineInfo = $db->find("select `merchant_id`,`state`,`is_delete`,`doorboard_img_id`,`merchant_name`,section_id from `ysmz_merchant_offline` where `merchant_id`=$sid");
            if(empty($offlineInfo)){
                Result::error("商家不存在");
            }
            if($offlineInfo["state"] != 1 || $offlineInfo["is_delete"] != 0 ){
                Result::error("商家未审核或已删除");
            }

            $info["name"] = $offlineInfo["merchant_name"];
            $fileInfo = $db->find("select `file_id`,`storage`,`domain`,`file_path` from `ysmz_file` where `file_id` =$offlineInfo[doorboard_img_id]");
            $info["img_url"] = Common::fileUrl($fileInfo);
            $info["paymentMethod"] = getPaymentMethod($db, $offlineInfo["section_id"]);
            break;
        case 2:
            $shopInfo = $db->find("select `shop_id`,`status`,`shop_logo`,`shop_title`,section_id from `ysmz_shop` where `shop_id`=$sid");
            if(empty($shopInfo)){
                Result::error("店铺不存在");
            }
            if($shopInfo["status"] != 1){
                Result::error("店铺已暂停运营");
            }
            $info["name"] = $shopInfo["shop_title"];
            $info["img_url"] = $shopInfo["shop_logo"];
            $info["paymentMethod"] = getPaymentMethod($db, $shopInfo["section_id"]);
            break;
        default:Result::error("未知商家");break;
    }
    Result::success($info);
}
function queryShopInfo($sid,$type)
{
    $db = new Db();
    switch ($type) {
        case 1:
            $shopInfo = $db->find("select `merchant_name` from `ysmz_merchant_offline` where `merchant_id`=$sid");
            break;
        case 2:
            $shopInfo = $db->find("select `shop_id`,`status`,`shop_logo`,`shop_title`,`contact_mobile`,`kefu_phone`,`kefu_weixin` from `ysmz_shop` where `shop_id`=$sid");
            break;
        default:$shopInfo=[];
    }
    return $shopInfo;
}